<?php
/**
 * Created by PhpStorm.
 * User: 10037
 * Date: 2022/5/26
 * Time: 22:29
 */

namespace app\admin\controller;



use app\admin\model\User;
use thans\jwt\facade\JWTAuth;
use think\captcha\facade\Captcha;
use think\facade\Request;

class Login
{
    public function verify(){
        return Captcha::create('base64');
    }

    public function detectVerify(){
        $capha=Request::post('capha');
        $caphaKey=Request::post('caphaKey');
        if(!Captcha::check($capha,$caphaKey)){
            return false;
        }else{
            return true;
        };
    }

    public function userLogin(){
        $username=Request::post('username');
        $password=Request::post('password');

        $mode=new User();

        $result= $mode->selectIsUser($username,$password);

        if($result['flag']){
            $token= JWTAuth::builder(['id'=>2]);
            return json([
                'message'=>'登陆成功',
                'token'=>$token,
                'status'=>true,
                'id'=>$result['id'],
                'userImg'=>$result['img'],
                'userName'=>$username
            ]);
        }else{
            return json(
                [
                    'message'=>'登陆失败',
                    'status'=>false
                ]
            );
        }
    }
}